﻿using System;
using System.Web;
using System.Web.Mvc;

namespace AgileBoard.Web.Controllers.Util
{
    public class ExtJsJsonReaderResult : JsonResult
    {
        public ExtJsJsonReaderResult(string rootName, object orderDataObjects)
        {
            RootName = rootName;
            Data = orderDataObjects;
        }

        public string RootName { get; set; }

        public override void ExecuteResult(ControllerContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            HttpResponseBase response = context.HttpContext.Response;

            //response.ContentType = !string.IsNullOrEmpty(ContentType) ? 
            //                                                            ContentType : "application/json";

            //if (ContentEncoding != null)
            //  response.ContentEncoding = ContentEncoding;

            if (Data != null)
                response.Write(Data.ToExtJsJsonReader(RootName));
        }
    }
}